var countryid;
$.getJSON('../profile/' + userid, function(data) {
    if (!data.error) {
        $(".name").val(data.name);
        $(".lastname").val(data.lastname);
        $('.sex option[value=' + data.sex + ']').attr('selected', 'selected');
        $(".address").val(data.address);
        $(".zipcode").val(data.zipcode);
        $(".city").val(data.city);
        $(".birthdate").val(data.birthdate);
        $(".religion").val(data.religion);
        countryid=data.countryid;
    } else {
        alert("404 Cannot find profile.");
    }
});

$(".id").val(userid);
$('#submit').click(function() {
    $.post('../profile_edit', $("#profile_edit_form").serialize(), function(data) {
        console.log(data);
    });
});

$.getJSON('../countries', function(data) {
    var clist = "";
    $.each(data, function(key, value) {
        clist = clist + "<option value=\"" + value.id + "\">" + value.name + "</option>";
    });
    $('#countries').html(clist);
    $('#countries option[value=' + countryid + ']').attr('selected', 'selected');
});
